package com.v5ba.sms;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @author yiren
 * @since 2022/9/12
 */
public class MyCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        // 维护Bean定义，可以修改、新增和删除
        BeanDefinitionRegistry registry = context.getRegistry();
        //RootBeanDefinition beanDefinition = new RootBeanDefinition(OrgService.class);
        //registry.registerBeanDefinition("orgService", beanDefinition);

        // 获取环境变量
        Environment environment = context.getEnvironment();
        String name = environment.getProperty("name");

        return false;
    }
}
